package com.easy.controller;

import com.easy.bean.Product;
import com.easy.service.IProductService;
import com.easy.util.LayData;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("product")
public class ProductController {
    @Autowired
    IProductService productService;
    @RequestMapping("list")
    @ResponseBody
    public LayData getList(Product product, Page page){
        List list=productService.getList(product,page);
        int count=productService.count(product);
        return LayData.success(count,list);
    }

    @RequestMapping("random")
    @ResponseBody
    public LayData random(Integer categoryid,Integer count){
        List list=productService.random(categoryid,count);
        return LayData.success(list);
    }

    @RequestMapping("getproduct")
    @ResponseBody
    public LayData getList(Integer id){
        Product product=productService.getProductByID(id);
        return LayData.success(product);
    }
}
